package com.xuhai.movie.controller;

import com.xuhai.movie.bean.Movie;
import com.xuhai.movie.service.MovieService;
import com.xuhai.movie.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author PangJunjie
 * @Date 2022/4/13/013
 */
@RestController
@RequestMapping("/movie")
public class MovieController {

    @Autowired
    private MovieService movieService;

    @GetMapping("/page")
    public ResultJson page(int page, int limit, Movie movie){
        return movieService.getPage(page, limit, movie);
    }

    @GetMapping("/info/{movieId}")
    public ResultJson info(@PathVariable Integer movieId){
        return movieService.getById(movieId);
    }

    @GetMapping("/{movieId}/image")
    public ResultJson movieImage(@PathVariable Integer movieId){
        return movieService.getImageListByMovieId(movieId);
    }

    @GetMapping("{movieId}/category")
    public ResultJson movieCategory(@PathVariable Integer movieId){
        return movieService.getCategoryListByMovieId(movieId);
    }


    @PostMapping("/update")
    public ResultJson update(@RequestBody Movie movie){
        movieService.saveOrUpdate(movie);
        return ResultJson.ok();
    }

    @DeleteMapping("/delete/{movieId}")
    public ResultJson delete(@PathVariable Integer movieId){
        movieService.deleteById(movieId);
        return ResultJson.ok();
    }

    @PostMapping("/status")
    public ResultJson status(@RequestBody Movie movie){
        movieService.status(movie);
        return ResultJson.ok();
    }
}
